
//路由中间件
const expess = require('express')
const router = expess.Router()
const { getList, createUser } = require('../controller/blog')

const { SuccessModel } = require('../model/responseModel')

router.get('/getlist', (req, res) => {
    const author = req.query.author
    const keyword = req.query.keyword
    const listPromise = getList(author, keyword)
    return listPromise.then(listData => {
        res.send(new SuccessModel(listData)
        )
    })
})
router.post('/createUser', (req, res) => {
    const { name, pwd } = req.query;
    const newUserData = createUser(name, pwd)
    return newUserData.then(listData => {
        console.log(listData)
        res.send(new SuccessModel(listData)
        )
    })
})

// router.get('/index', (req, res, next) => {
//     const query = req.query
//     res.send(query)
// })
// router.post('/index', (req, res, next) => {
//     const data = req.body
//     console.log('data', data)
//     res.send(data)
//     // return new SuccessModel(data)
// })


module.exports = router